<include file="public@header" />
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li class="active"><a href="{:url('student/index')}">所有学生</a></li>
			<li><a href="{:url('student/add')}">添加学生</a></li>
		</ul>
		<form class="well form-inline margin-top-20"  method="get" action="{:url('student/index')}">
			学校名称:
			<select name="school_id" id="selectSchool" class="form-control">
				<option value="">请选择学校</option>
				<volist name="school" id="vo">
					<php> $selectedSchool = $vo['id'] == $school_id ? "selected" : "";</php>
					<option value="{$vo.id}" {$selectedSchool}>{$vo.name}</option>		
				</volist>
			</select>
			班级名称:
			<select name="room_id" class="form-control" id="room">
				<option value="">请选择班级</option>
				<volist name='room' id="vo">
					<php> $selectedRoom = $vo['id'] == $room_id ? "selected" : "";</php>
					<option value="{$vo.id}" {$selectedRoom}>{$vo.name}</option> 
			   </volist>
			</select>
			学生姓名:
			<input type="text" class="form-control" name="name"  style="width: 200px;" value="{$Request.param.name}" placeholder="请输入学生名称">
			<input type="submit" class="btn btn-primary" value="搜索" />
			<a class="btn btn-danger" href="{:url('student/index')}">清空</a>
		</form>
		<form method="post" class="js-ajax-form margin-top-20" action="{:url('student/delAll')}">
			<div class="table-actions">
				<button class="btn btn-sm btn-danger js-ajax-submit" type="submit"
						data-action="{:url('student/delAll')}" data-subcheck="true">批量删除
				</button>
			</div>
		<table class="table table-hover table-bordered">
			<thead align="center">
				<tr>
					<th width="16"><label><input type="checkbox" class="js-check-all" data-direction="x"
						data-checklist="js-check-x"></label></th>
					<th width="60">ID</th>
					<th>头像</th>
					<th>姓名</th>
					<th>性别</th>
					<th>年龄</th>
					<th>手机号</th>
					<th>身份证号</th>
					<th>所属班级</th>
					<th>所属学校</th>
					<th>修改时间</th>
					<th>创建时间</th>
					<th>量化积分</th>
					<th width="160">{:lang('ACTIONS')}</th>
				</tr>
			</thead>
			<tbody>
				<foreach name="student" item="vo">
					<tr>
						<td><input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
							value="{$vo.id}"></td>
						<td>{$key+1}</td>
						<td>
							<eq name="$vo.image" value="">
								暂无
							<else/>
								<img src="__ROOT__/upload/{$vo.image}" width="100px">
							</eq>
						</td>
						<td>{$vo.name}</td>
						<eq name='$vo.sex' value='1'>
							<td>男</td>
						<else>
							<td>女</td>
						</else>
						</eq>
						<td>{$vo.age}</td>
						<td>{$vo.mobile}</td>
						<td>{$vo.idcard}</td>
						<td>{$vo.room_name}</td>
						<td>{$vo.school_name}</td>
						<td>{$vo.upload_time}</td>
						<td>{$vo.create_time}</td>
						<eq name='$vo.total' value= ''>
                            <td>0</td>
                        <else>
							<td>{$vo.total}</td>
						</else>
						</eq>
						<td>
							<a class="btn btn-xs btn-primary" href="{:url('student/grade', array('id'=>$vo['id']))}">成绩</a>
							<a class="btn btn-xs btn-success" href="{:url('student/edit', array('id'=>$vo['id']))}">编辑</a>
							<a class="btn btn-xs btn-danger js-ajax-delete" href="{:url('student/delete', array('id'=>$vo['id']))}">删除</a>
						</td>
					</tr>
				</foreach>
			</tbody>
		</table>
		<div class="pagination">{$page}</div>
		</form>
	</div>
	<script src="__STATIC__/js/admin.js"></script>
	<script src="__STATIC__/layui/layui.all.js"></script>
	<script>
		$(function () {
		   
			$('#selectSchool').change('click',function () {
				
				var schoolId=$('#selectSchool').val();
				
				$.ajax({
					url:"{:url('student/getRoom')}",
					type:"POST",
					data:{school_id:schoolId},
					success:function (res) {
						console.log(res);
						$('#room').html(res);
					}
				});
			});
		})
	</script>
	<script>
		layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
          // 监听全选
          form.on('checkbox(checkall)', function(data){

              if(data.elem.checked){
                  $('tbody input').prop('checked',true);
              }else{
                  $('tbody input').prop('checked',false);
              }
              form.render('checkbox');
          });
	  });
	  
		//多选删除
		function delAll() {
          var ids = [];

          //获取选中的id
          $('tbody input').each(function (index,el) {
              if ($(this).prop('checked')){
                  ids.push($(this).val())
              }
          });
          layer.confirm('确认要删除吗?',function (index) {
              //捉到所有被选中的，发异步进行删除
              $.ajax({
                  url: "{:url('student/delAll')}",
                  type: "POST",
                  data: {ids:ids},
                  success: function (res) {
                      if (res.code == 200){
                          layer.msg(res.msg,{icon:1});
                          setTimeout(function () {
                              location.reload();
                          },1500);
                      } else {
                          layer.msg(res.msg);
                          return false;
                      }
                  }
              });
          });
      }
	</script>
</body>
</html>